import { searchUser, searchArticle } from 'assets/js/api';

// 用户信息 mixins
export const userInfoMixins = {
    data () {
        return {
            userInfo: {}
        };
    },
    mounted () {
        this.searchUser();
    },
    methods: {
        searchUser () {
            searchUser({}).then(res => {
                this.userInfo = res.data[0];
            });
        }
    }
}
;

// 查询文章列表 mixins
export const searchArticleMixins = {
    data () {
        return {
            articleList: []
        };
    },
    mounted () {
        this.searchArticle(this.paramsJson).then(res => {
            this.articleList = res;
        }).catch(error => {
            this.$Message.info(error);
        });
    },
    methods: {
        showArticleDetail (index, row) {
            this.$router.push({
                path: `/index/articleDetail`,
                query: {
                    articleId: row._id
                }
            });
        },
        searchArticle (paramsJson) {
            return new Promise((resolve, reject) => {
                searchArticle(paramsJson).then(res => {
                    if (!res.status) {
                        reject(res.msg);
                    }
                    resolve(res.data);
                });
            });
        }
    }
}
;
